<div id="panel-button" class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body text-right">
				<div class="col-sm-4 pull-left">
					{{Form::text('filter', null, array('id' => 'filter', 'class' => 'form-control', 'placeholder' => trans('form.filter')))}}
				</div>
				{{Form::button(trans('form.create'), array('class' => 'btn btn-success', 'id' => 'create'))}}
			</div>
		</div>
	</div>
</div>

<div id="panel-button-fixed" class="row hidden">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body text-right">
				<div class="col-sm-4 pull-left">
					{{Form::text('filter', null, array('id' => 'filter', 'class' => 'form-control', 'placeholder' => trans('form.filter')))}}
				</div>
				{{Form::button(trans('form.create'), array('class' => 'btn btn-success', 'id' => 'create'))}}
			</div>
		</div>
	</div>
</div>

@if(Session::has('error'))
	<div id="panel-error" class="row hidden">
		<div class="col-md-12">
			<div class="panel panel-red panel-minimal">
				<header class="panel-heading">{{trans('form.form_error')}}</header>
				<div id="error-content" class="panel-body">
					{{Session::get('message', 'Something is error!')}}
				</div>
			</div>
		</div>
	</div>
@endif
<div class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body">
				<div class="table-responsive">
					<table class="table table-striped footable" data-filter="#filter" data-page-size="10" data-filter-minimum="1">
						<thead>
							<tr>
								<th>#</th>
								<th>{{trans('order.customer_name')}}</th>
								<th>{{trans('order.date')}}</th>
								<th data-type="numeric">{{trans('order.subtotal')}}</th>
								<th data-type="numeric">{{trans('order.dept')}}</th>
								<th data-type="numeric">{{trans('order.totalpay')}}</th>
								<th data-type="numeric">{{trans('order.refund')}}</th>
								<th data-type="numeric">{{trans('order.remaining')}}</th>
								<th>{{trans('form.tool')}}</th>
								<th>{{trans('form.delete')}}</th>
							</tr>
						</thead>
						<tbody>
							<?php
								$total     = 0;
								$dept      = 0;
								$totalpay  = 0;
								$refund    = 0;
								$remaining = 0;
							?>
							@foreach($orders as $row)
							<?php
								$total     += $row['total'];
								$dept      += $row['dept'];
								$totalpay  += $row['totalpay'];
								$refund    += $row['refund'];
								$remaining += $row['remaining'];
							?>
							<tr id="order" data-id="{{$row['id']}}">
								<td>{{$row['order_number']}}</td>
								<td>{{$row['name']}}</td>
								<td>{{date("d-m-Y", strtotime($row['date']))}}</td>
								<td style="width: 90px;" class="text-right">
									<strong>{{MoneyFormat::format($row['total'])}}</strong>
								</td>
								<td style="width: 90px;" class="text-right">
									<strong>{{MoneyFormat::format($row['dept'])}}</strong>
								</td>
								<td style="width: 90px;" class="text-right">
									<strong>{{MoneyFormat::format($row['totalpay'])}}</strong>
								</td>
								<td style="width: 90px;" class="text-right">
									<strong>{{MoneyFormat::format($row['refund'])}}</strong>
								</td>
								<td style="width: 90px;" class="text-right">
									<strong>{{MoneyFormat::format($row['remaining'])}}</strong>
								</td>
								<td class="text-right">
									{{Form::button(trans('form.print'), array('class' => 'btn btn-xs btn-info', 'id' => 'print', 'data-id' => $row['id']))}}
									<br />
									{{Form::button(trans('form.print_address'), array('class' => 'btn btn-xs btn-success', 'id' => 'print_address', 'data-customer' => $row['customer']))}}
									<br />
									{{Form::button(trans('form.export'), array('class' => 'btn btn-xs btn-yellow', 'id' => 'export', 'data-id' => $row['id']))}}
								</td>
								<td class="text-center">
									{{Form::button(trans('form.delete'), array('class' => 'btn btn-xs btn-danger', 'id' => 'delete', 'data-id' => $row['id']))}}
								</td>
							</tr>
							@endforeach
						</tbody>
						<tfoot>
							<tr>
								<td colspan="10" class="text-right">
									<ul class="pagination pagination-sm"></ul>
								</td>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(document).ready(function() {
	$("tr#order").click(function(){
		var id = $(this).attr('data-id');
		var url = '{{URL::to("admin/order/edit")}}' + "/" + id;

		window.location = url;
	});

	$("button#add_order_include").click(function(event) {
		/* Act on the event */
		var id = $(this).attr('data-id');
		var url = "{{URL::to('admin/order-include/create')}}" + "/" + id;

		window.location = url;

		return false;
	});

	$("button#print").click(function(event) {
		/* Act on the event */
		var id = $(this).attr('data-id');
		var url = "{{URL::to('admin/order/print/')}}" + "/" + id;

		window.location = url;

		return false;
	});

	$("button#print_address").click(function(event) {
		/* Act on the event */
		var id = $(this).attr('data-customer');
		var url = "{{URL::to('admin/customer/print-address/')}}" + "/" + id;

		window.location = url;

		return false;
	});

	$("button#export").click(function(event) {
		/* Act on the event */
		var id = $(this).attr('data-id');
		var url = "{{URL::to('admin/export/index/')}}" + "/" + id;

		window.location = url;

		return false;
	});

	$("button#delete").click(function() {
		var name = $(this).attr('data-name');
		var ok = confirm("{{trans('order.confirm_delete')}}");

		if(ok){
			var id = $(this).attr('data-id');

			$.ajax({
				url: '{{URL::to("admin/order/delete")}}',
				type: 'POST',
				data: {'id': id},
				success: function(result){
					var rs = $.parseJSON(result);

					if(rs.error == false){
						window.location.reload();
					}else{
						alert(rs.message);
					}
				}
			});
		}

		return false;
	});

	$("button#create").click(function(){
		var url = "{{URL::to('admin/order/create/' . $type)}}";

		window.location = url;
	});

	$('.footable').footable();
});
</script>
<style type="text/css">
table thead th{
	text-align: center;
}

table tbody{
	height: 100px;
	overflow: hidden;
}

.number{
	width: 95px;
	text-align: right;
}
</style>